/*
 * @(#)TranResult.java 1.0 2012-8-9
 *
 * Copyright @2011-2011 Gopay Information and Technology Co., Ltd.
 * Sanyunqiao, Chaoyang, Beijing, 100027, China.
 * All Rights Reserved.
 *
 * This software is the confidential and proprietary information of
 * Gopay Information and technology Co., Ltd. ("Confidential Information").
 * You shall not disclose such Confidential Information and shall use it only in
 * accordance with the terms of the license agreement you entered into with Gopay.
 */
package com.gopay.common.domain.acps;

import java.io.Serializable;
import java.util.Arrays;

/**
 * 账户系统处理结果
 * 
 * @author zhanglei
 * @version 1.0 2012-8-9
 */
public class TranResult implements Serializable {
    private static final long serialVersionUID = 5813779457156028574L;
    public static final String LF = System.getProperty("line.separator");
    /** 处理是否成功 **/
    private boolean success;
    /** 单号 **/
    private String orderId;
    /** 账务流水ID，对应于TranDetail.id **/
    private String tranId;
    /** 处理结果 **/
    private String message;
    /** 处理失败-错误代码 **/
    private String errorCode;
    /** 处理失败-概要信息（比如展示给最终用户的信息） **/
    private String errorSummary;
    /** 处理失败-错误详细信息（比如供技术人员使用的信息） **/
    private String errorDetail;

    public TranResult(boolean success, String orderId, String errorCode, String errorSummary, Exception e) {
        super();
        this.success = success;
        this.orderId = orderId;
        this.errorCode = errorCode;
        this.errorSummary = errorSummary;
        if (null != e) {
            StringBuffer s = new StringBuffer();
            s.append(e.getClass()).append(" : ");
            s.append(e.getMessage()).append(LF);
            if (null != e.getStackTrace()) {
                s.append(Arrays.toString(e.getStackTrace()).replaceAll(", ", LF).replaceAll("\\[", "")
                        .replaceAll("\\]", ""));
            }
            this.errorDetail = s.toString();
        }
    }

    public TranResult(boolean success, String orderId, String errorCode, String errorSummary, Exception e, String tranId) {
        super();
        this.success = success;
        this.orderId = orderId;
        this.errorCode = errorCode;
        this.errorSummary = errorSummary;
        if (null != e) {
            StringBuffer s = new StringBuffer();
            s.append(e.getClass()).append(" : ");
            s.append(e.getMessage()).append(LF);
            if (null != e.getStackTrace()) {
                s.append(Arrays.toString(e.getStackTrace()).replaceAll(", ", LF).replaceAll("\\[", "")
                        .replaceAll("\\]", ""));
            }
            this.errorDetail = s.toString();
        }
        this.tranId = tranId;
    }

    public TranResult(boolean success, String orderId, String errorCode, String errorSummary) {
        super();
        this.success = success;
        this.orderId = orderId;
        this.errorCode = errorCode;
        this.errorSummary = errorSummary;
    }

    public TranResult(boolean success, String orderId, String errorCode, String errorSummary, String errorDetail) {
        super();
        this.success = success;
        this.orderId = orderId;
        this.errorCode = errorCode;
        this.errorSummary = errorSummary;
        this.errorDetail = errorDetail;
    }

    public TranResult(boolean success, String orderId) {
        super();
        this.orderId = orderId;
        this.success = success;
    }

    public TranResult(boolean success, String orderId, String message) {
        super();
        this.success = success;
        this.orderId = orderId;
        this.message = message;
    }

    public TranResult(boolean success) {
        super();
        this.success = success;
    }

    /**
     * 默认构造器中的success为true；
     */
    public TranResult() {
        super();
        this.success = true;
    }

    public boolean isSuccess() {
        return success;
    }

    public void setSuccess(boolean success) {
        this.success = success;
    }

    public String getErrorCode() {
        return errorCode;
    }

    public void setErrorCode(String errorCode) {
        this.errorCode = errorCode;
    }

    public String getErrorSummary() {
        return errorSummary;
    }

    public void setErrorSummary(String errorSummary) {
        this.errorSummary = errorSummary;
    }

    public String getErrorDetail() {
        return errorDetail;
    }

    public void setErrorDetail(String errorDetail) {
        this.errorDetail = errorDetail;
    }

    public String getOrderId() {
        return orderId;
    }

    public void setOrderId(String orderId) {
        this.orderId = orderId;
    }

    @Override
    public String toString() {
        return "TranResult [success=" + success + ", orderId=" + orderId + ", errorCode=" + errorCode
                + ", errorSummary=" + errorSummary + ", errorDetail=" + errorDetail + "]";
    }

    public String getMessage() {
        return message;
    }

    public void setMessage(String message) {
        this.message = message;
    }

    public String getTranId() {
        return tranId;
    }

    public void setTranId(String tranId) {
        this.tranId = tranId;
    }

}
